<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <script>
        function save(){
            var value1=document.getElementById("account").value.trim()
            var value2=document.getElementById("password1").value.trim()
            var value3=document.getElementById("password2").value.trim()
            var users={
                account:value1,
                password:value2
            }
            if (value1 == ""){
                document.getElementById("showTipMsgAccount").innerText = "*必填";
                return;
            }
            if (value2 == ""){
                document.getElementById("showTipMsgpassword1").innerText = "*必填";
                return;
            }
            if (value3 == ""){
                document.getElementById("showTipMsgrepassword2").innerText = "*必填";
                return;
            }
            if(value2!=value3){
                document.getElementById("showTipMsgrepassword2").innerText = "两次密码不一致";
                return;
            }
            // $.ajax({
            //     url:"user/search",
            //     data:{
            //         account:value1
            //     },
            //     method:"post",
            //     success:function (res){
            //         console.log(res)
            //         if(res!=null){
                        $.ajax({
                                url:"user/regist",
                                data:JSON.stringify(users),

                                method:"post",
                                contentType:"application/json;charset=utf-8",

                                success:function (item){

                                    if(item=="Y"){
                                        alert("注册成功！去登录吧！")
                                    }else {
                                        alert("注册遇到问题~")
                                    }
                                }
                            })

            //          }else {
            //              alert("用户名已被占用，更改用户名！")
            //          }
            //     }
            //
            // })

        }
        function search(account){
            var account=document.getElementById("account").value.trim()

            $.ajax({
                url:"user/search",
                data: {account:account},
                method:"post",

                dataType:"json",
                success:function (res) {
                    console.log(res)
                    if (res != null) {
                        $("#account").val('');
                        $("#password1").val('');
                        $("#password2").val('');
                        alert("用户名已被占用，更改用户名！")

                    }

                }

            })

        }
    </script>
</head>
<body>
    <div class="registaccount" style="text-align: center;margin-top: 30px">
        账号：<input type="text" id="account" placeholder="账号"></input>
        <span id="showTipMsgAccount" style="color: red;font-size: 12px"></span><br>
    </div>
    <div class="registpassword" style="text-align: center;margin: 5px 0px 10px 0px">
        密码：<input type="password" id="password1" placeholder="密码" onblur="search()"></input>
        <span id="showTipMsgpassword1" style="color: red;font-size: 12px"></span><br>
        确认密码：<input type="password" id="password2" placeholder="确认密码"></input>
        <span id="showTipMsgrepassword2" style="color: red;font-size: 12px"></span><br>

    </div>
    <div class="registbutton" style="text-align: center;margin-top: 30px">
        <button type="button" class="btn btn-primary" onclick="save()">注册</button>
        <button type="reset" class="btn btn-danger">重置</button><br>

    </div>
    <div class="registbody" style="text-align: center;margin-top: 30px"><a href="login.html">已有账号？去登录！</a></div>



</body>
</html>